<template>
  <div class="submit-page">
    <el-card class="submit-card">
      <h3>问题/需求提交</h3>
      <el-form ref="form" :model="formData" label-width="120px">
        <el-form-item label="问题描述">
          <el-input
            type="textarea"
            v-model="formData.description"
            placeholder="请输入问题或需求的详细描述"
          ></el-input>
        </el-form-item>

        <el-form-item label="附件上传">
          <el-upload
            class="upload-demo"
            drag
            action="#"
            :auto-upload="false"
            :file-list="fileList"
            :on-remove="handleRemoveFile"
            :on-change="handleChangeFile"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">点击或拖动文件上传</div>
          </el-upload>
        </el-form-item>

        <el-form-item label="问题分类">
          <el-select v-model="formData.category" placeholder="请选择问题分类">
            <el-option label="技术支持" value="tech-support" />
            <el-option label="合同咨询" value="contract" />
            <el-option label="设备维护" value="maintenance" />
            <el-option label="财务问题" value="finance" />
            <el-option label="其他" value="other" />
          </el-select>
        </el-form-item>

        <el-form-item label="优先级">
          <el-radio-group v-model="formData.priority">
            <el-radio label="low">低</el-radio>
            <el-radio label="medium">中</el-radio>
            <el-radio label="high">高</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">提交问题</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {
        description: '',
        category: '',
        priority: 'low'
      },
      fileList: []
    }
  },
  methods: {
    submitForm() {
      const newIssue = {
        ...this.formData,
        submitTime: new Date().toLocaleString(),
        status: '待处理',
        progress: '问题正在处理...',
        id: Date.now()
      }
      this.$router.push({ name: 'View' }) // 提交后跳转到查看页面
    },
    handleRemoveFile(file) {
      const index = this.fileList.indexOf(file)
      if (index !== -1) {
        this.fileList.splice(index, 1)
      }
    },
    handleChangeFile(file, fileList) {
      this.fileList = fileList
    }
  }
}
</script>

<style scoped>
.submit-page {
  padding: 20px;
}

.submit-card {
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
</style>
